﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace desktop01
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private static FrameworkElement _frameworkElement;
        public MainWindow()
        {
            InitializeComponent();
        }

        private double operate(string method, double va1, double va2)
        {
            if (Equals(method,"+"))
            {
                return va1+va2;
            }

            if (Equals(method,"-"))
            {
                return va1 - va2;
            }

            if (Equals(method,"*"))
            {
                return va1 * va2;
            }

            if (Equals(method,"/"))
            {
                return va1 / va2;
            }

            return 0;
        }
        
        
        
        private long operate(string method, long va1, long va2)
        {
            if (Equals(method,"+"))
            {
                return va1+va2;
            }

            if (Equals(method,"-"))
            {
                return va1 - va2;
            }

            if (Equals(method,"*"))
            {
                return va1 * va2;
            }

            if (Equals(method,"/"))
            {
                return va1 / va2;
            }

            return 0;
        }

        private string checkRadio()
        {
            if (add.IsChecked.Value)
            {
                return "+";
            }

            if (substract.IsChecked.Value)
            {
                return "-";
            }

            if (multiple.IsChecked.Value)
            {
                return "*";
            }

            if (divide.IsChecked.Value)
            {
                return "/";
            }

            return "+";
        }

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            long temp1 = 0;
            long temp2 = 0;
            double tempf1 = 0;
            double tempf2 = 0;
            bool isOk = true;
            string op = checkRadio();
            if (long.TryParse(number1.Text, out temp1))
            {
                if (long.TryParse(number2.Text, out temp2))
                {
                    label.Content = "Answer: " + operate(op,temp1,temp2).ToString();
                    return;
                }
            }
            else
            {
                isOk = double.TryParse(number1.Text, out tempf1);
                isOk = double.TryParse(number2.Text, out tempf2);
            }

            if (isOk)
            {
                label.Content = "Answer: " + (operate(op,tempf1,tempf2).ToString());
            }
            else
            {
                MessageBox.Show("Error Input");
                number1.Text = "";
                number2.Text = "";
                label.Content = "Answer: ";
            }
        }
    }
}